<?php
/**
 * @name ss_SimilarFiles
 * @author Dani Remeseiro
 * @abstract class to fetch Related Files to a file name , filename passed as param
 * to be used on MP3 file single view by mp3 extension
 * @param nameFile (int)
 * @param idparent  (int)
 * 
 */

global $IP;

require_once( $IP.'/includes/WebStart.php' );
require_once($IP.'/includes/SoundShareUtils.php');

class ss_SimilarFiles {

  
    function __construct() {  //needed by php 5.2 - Dont remove!
    }

    
  
    public static function ss_SimilarFiles($file){
      
      global $wgScript, $wgRequest;
     
	$dbr = wfGetDB( DB_SLAVE );
        $sql = "select ss.* from ss_file_with_song ss inner join ss_song_file ss2 on ss.idsong = ss2.idsong where ss2.IdFile={$file->IdFile} and ss.idfile!={$file->IdFile} order by count desc limit 100;";
        $ss_res = $dbr->query( $sql );
                   
        $out = '<div class ="similar-files">Similar files:<br />'; 
        $out .= '<div class ="similar-files-scroll" style="height:170px; overflow: auto; ">';
         
        while ($row = $dbr->fetchobject($ss_res)) {
        	$out .= '<span><a href='.$wgScript.'/Special:MP3/'.$row->IdFile.'>'.$row->Filename.'</a><br>
                          <small>size: '.ByteSize( $row->Size ).', lenght: '.convertS2String( $row->Length ).', bitrate: '.$row->Bitrate.'</small>
                          </span>';
        } 
         
        $dbr->freeResult($ss_res);
        $out .= '</div></div>';
                
        return  $out;
    }
}
